<template>
  <div class="card">
    <div class="media_box" :style="{ height: props.height }">
      <img
        v-if="props.type === 'img'"
        :src="props.url"
        :style="{ height: props.height }"
      />
      <video v-if="props.type === 'video'" class="video" muted loop autoplay>
        <source :src="props.url" :data-src="props.url" type="video/mp4" />
      </video>
      <div class="rotation_cladding" :style="{ height: props.height }">
        <div class="rotation_cladding_head">
          <ul class="icons" v-if="props.canLink">
            <li
              v-for="(o, i) in links"
              :key="i"
              class="icon iconfont icon_item"
              :class="o.icon"
            />
          </ul>
          <div class="coll" v-if="props.canColl">{{ $t('message.coll') }}</div>
        </div>
        <div class="center" v-if="props.canRate">
          {{ $t('message.rateNow') }}
        </div>
        <div
          class="icon iconfont icon-bilibili share"
          v-if="props.canShare"
        ></div>
      </div>
    </div>
    <!-- 图片下面内容可自定义 -->
    <slot></slot>

    <div id="des_box" v-if="!props.hasSlot">
      <div class="name">Pyramids of Meroë</div>
      <div class="des">
        <div class="pos">{{ $t('message.command.2') }} United Kingdom</div>
        <div class="time">{{ curDate }}</div>
      </div>
    </div>
    <div class="footer">
      <div class="img_box">
        <img
          class="head_icon"
          @mouseenter="mouseenterEn"
          @mouseleave="mouseleaveEn"
          src="@/assets/head-icon.jpg"
          alt="图标"
        />
        <TooltipComp
          v-bind="{
            display: display,
            disTop: disTop,
            hasSlot: true,
          }"
        >
          <img class="hover_head_icon" src="@/assets/head-icon.jpg" alt="" />
          <div class="name">Panowie Pro</div>
          <div class="from">Poland</div>
        </TooltipComp>
      </div>
      {{ $t('message.command.1') }}
      <div class="mark">ELEGANT SEAGULLS</div>
      <div class="tag_list" v-if="props.hasTag">
        <div class="tag">HM</div>
        <div class="tag">DEV</div>
        <div class="tag">SOTD</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { links } from '@/views/Home/config';
import { convertDayjs } from '@/utils/commonApi';
import TooltipComp from '@/components/tooltip.vue';
import { ref } from 'vue';

interface Props {
  height?: string;
  url: string;
  type: 'img' | 'video';
  canLink: boolean;
  canColl: boolean;
  canRate: boolean;
  canShare: boolean;
  hasTag: boolean;
  hasSlot?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
  height: '280px',
  canLink: false,
  canColl: false,
  canRate: false,
  canShare: false,
  hasSlot: false,
});
const curDate = convertDayjs();

const disTop = ref(0);
const display = ref(false);
const mouseenterEn = (e: MouseEvent) => {
  disTop.value = e.clientY;
  display.value = true;
  console.log('?????', display.value);
};
const mouseleaveEn = (e: MouseEvent) => {
  display.value = false;
};
</script>

<style lang="scss" scoped>
.card {
  margin-right: 3.33%;
  width: 30%;
  background-color: #fcfcfc;
  margin-bottom: 30px;
}

.media_box {
  position: relative;
  cursor: pointer;
  overflow: hidden;

  &:hover {
    .rotation_cladding {
      display: block;
    }

    img {
      transform: scale(1.1);
    }
  }

  img {
    width: 100%;
    transition: transform 0.5s;
  }
  .video {
    width: 100%;
    // height: 280px;
  }

  .rotation_cladding {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    transition: all 0.5s;
    display: none;
    box-sizing: border-box;
    padding: 30px 20px;

    &_head {
      display: flex;
      justify-content: space-between;
    }

    .icons {
      display: flex;
    }

    .icon_item {
      font-size: 20px;
      width: 38px;
      height: 38px;
      text-align: center;
      line-height: 38px;
      border-radius: 50%;
      border: 1px solid #fff;
      margin: 0 4px;
      @include hoverReduceOp(0.6);
    }

    .coll {
      padding: 0 10px;
      height: 38px;
      line-height: 38px;
      text-align: center;
      border-radius: 38px;
      color: #fcfcfc;
      border: 1px solid #fcfcfc;
      @include hoverReduceOp(0.6);
    }

    .center {
      width: 120px;
      height: 60px;
      border-radius: 60px;
      text-align: center;
      line-height: 60px;
      color: black;
      background-color: var(--vt-c-white);
      margin: 20px auto 0;
    }
    .share {
      position: absolute;
      right: 20px;
      bottom: 20px;
      font-size: 20px;
      width: 42px;
      height: 42px;
      text-align: center;
      line-height: 42px;
      border-radius: 50%;
      border: 1px solid #fff;
      margin: 0 4px;
    }
  }
}

#des_box {
  padding: 20px;
  border-bottom: 1px solid $main-border-color;

  .name {
    color: $primary-font-color;
    line-height: 40px;
  }

  .des {
    color: #64686a;
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    padding-bottom: 10px;
  }
}

.footer {
  display: flex;
  align-items: center;
  color: #64686a;
  height: 60px;
  font-size: 13px;

  .head_icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-left: 10px;
    margin-right: 4px;
    cursor: pointer;
  }
  .hover_head_icon {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    margin: 50px auto 30px;
  }
  .name {
    font-size: 16px;
    padding-bottom: 10px;
  }

  .img_box {
    position: relative;
  }

  .mark {
    padding-left: 6px;
    color: $primary-font-color;
    font-size: 13px;
    font-weight: bold;
  }
  .tag_list {
    display: flex;
    .tag {
      padding: 0 4px;
      height: 16px;
      border-radius: 16px;
      line-height: 16px;
      color: #fff;
      margin: 0 3px;
      cursor: pointer;

      &:nth-of-type(1) {
        background-color: #49c5b6;
      }

      &:nth-of-type(2) {
        background-color: #8154ef;
      }

      &:nth-of-type(3) {
        background-color: #ff4e4e;
      }
    }
  }
}
</style>
